package com.wdh.kjs.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ScrollView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.Adapter.TuijianAdapter;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.http.response.BannerListResponse;
import com.wdh.kjs.widget.BannerViewPager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by codingWw on 2016/3/7.
 */
public class HomePageFragment extends Fragment implements AdapterView.OnItemClickListener, View.OnTouchListener {

    private ListView listView;
    private TuijianAdapter adapter;
    private List<HashMap<String, String>> datas;
    private ScrollView scrollView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_chainwinfinance, container, false);
        initView(view);
        initwidge();
        return view;
    }

    private void initwidge() {
        adapter=new TuijianAdapter(getContext(),initListViewData());
        listView.setAdapter(adapter);
        listView.setOnTouchListener(this);
        listView.setOnItemClickListener(this);
    }

    private List<HashMap<String, String>> initListViewData() {
        datas = new ArrayList<>();

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("style", "【三农贷】");
        hashMap.put("name", "测试1号");
        hashMap.put("money", "剩余可投金额 ：￥500,000.00元");
        hashMap.put("per", "10%");
        hashMap.put("day", "90天");
        hashMap.put("total", "￥1,000,000.00元");
        hashMap.put("per1", "50%");

        HashMap<String, String> hashMap1 = new HashMap<>();
        hashMap1.put("style", "【政信贷】");
        hashMap1.put("name", "测试2号");
        hashMap1.put("money", "剩余可投金额 ：￥500,000.00元");
        hashMap1.put("per", "10%");
        hashMap1.put("day", "90天");
        hashMap1.put("total", "￥1,000,000.00元");
        hashMap1.put("per1", "50%");
        datas.add(hashMap);
        datas.add(hashMap1);

        for(int i=1;i<4;i++){
            HashMap<String, String> hashMap3 = new HashMap<>();
            hashMap3.put("style", "【三农贷】");
            hashMap3.put("name", "测试1号");
            hashMap3.put("money", "剩余可投金额 ：￥500,000.00元");
            hashMap3.put("per", "10%");
            hashMap3.put("day", "90天");
            hashMap3.put("total", "￥1,000,000.00元");
            hashMap3.put("per1", "50%");
            datas.add(hashMap3);
        }
        return datas;

    }

    private void initView(View view) {
        listView = (ListView) view.findViewById(R.id.shouye_liastview);
        scrollView = (ScrollView) view.findViewById(R.id.shouye_scrollview);
        scrollView.smoothScrollTo(0, 0);

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction()==MotionEvent.ACTION_DOWN){
            scrollView.requestDisallowInterceptTouchEvent(false);
            listView.requestDisallowInterceptTouchEvent(true);
        }
        else
            scrollView.requestDisallowInterceptTouchEvent(true);
        return false;
    }
}
